<template>
  <div>
    <div v-show="!isShowDetail">
      <jxf-titletip :title="title" @refreshPage="refreshPage"></jxf-titletip>
      <el-card class="mt20">
        <el-form :inline="true" :model="searchInfo" ref="searchInfo">
          <el-form-item label="转出单号:" prop="applyNo">
            <el-input v-model="searchInfo.applyNo" @keyup.enter.native="$refs['telphone'].focus()" clearable></el-input>
          </el-form-item>
          <el-form-item label="供应商企业账号:" prop="telphone">
            <el-input ref="telphone" v-model="searchInfo.telphone"
                      @keyup.enter.native="$refs['enterpriseName'].focus()" clearable></el-input>
          </el-form-item>
          <jxf-Date :startTime.sync="searchInfo.auditStartTime" :endTime.sync="searchInfo.auditEndTime"
                    label="结算时间段："></jxf-Date>
          <jxf-Date :startTime.sync="searchInfo.applyStartTime" :endTime.sync="searchInfo.applyEndTime"
                    label="转出申请时间段："></jxf-Date>
          <el-form-item>
            <el-button type="primary" @click="onSearch()">搜索</el-button>
          </el-form-item>
          <el-form-item>
            <el-button type="info" @click="resetForm('searchInfo')">重置</el-button>
          </el-form-item>
        </el-form>
      </el-card>
      <el-card class="jxf-table-card mt20">
        <div slot="header" class="clearfix">
          <span>数据列表</span>
          <div>
            <el-button type="primary" @click="exportInfo" :loading="isSuccess">导出</el-button>
          </div>
        </div>
        <jxf-table class="" :table="dataTable">
          <template slot="operation" slot-scope="scope">
            <el-button type="text" @click="showDetail(scope.row)">查看详情</el-button>
          </template>
        </jxf-table>
      </el-card>
      <jxf-pagination class="mt20" :pageTotal="pageTotal" :currentPage.sync='currentPage' :pageSize.sync="pageSize"
                      @currentPageChange="currentPageChange" @pageSizeChange="pageSizeChange"></jxf-pagination>
    </div>
     <AdvanceTransferSettlementDetail ref="AdvanceTransferSettlementDetail" v-show="isShowDetail" :isShowDetail.sync="isShowDetail" @getList="getList"></AdvanceTransferSettlementDetail>
  </div>
</template>

<script>
  import formatDate from '@/assets/js/formatDate'
  import AdvanceTransferSettlementDetail from './components/AdvanceTransferSettlementDetail'

  export default {
    name: "AdvanceTransferSettlement",
    components: {AdvanceTransferSettlementDetail},
    data() {
      return {
        title: "提前提现（转出）结算",
        searchInfoBack: {
          applyNo: "",
          telphone: "",
          applyStartTime: "",
          applyEndTime: "",
          auditStartTime: "",
          auditEndTime: ""
        },
        isSuccess: false,
        searchInfo: {
          applyNo: "",
          telphone: "",
          applyStartTime: "",
          applyEndTime: "",
          auditStartTime: "",
          auditEndTime: ""
        },
        dataTable: {},
        currentPage: 1,
        pageSize: 10,
        pageTotal: 0,
        isShowDetail: false,
        isShowAudit: false,
        auditInfo:{}
      }
    },
    methods: {
      init() {
        this.dataTable = {
          border: true,
          loading: true,
          tr: [
            {
              id: '1',
              label: '提前转出单号（提前提现）',
              width: '210',
              prop: 'applyNo'
            },
            {
              id: '2',
              label: '转出申请时间',
              width: '160',
              prop: 'applyTime'
            },
            {
              id: '3',
              label: '供应商企业名称',
              minWidth: '130',
              prop: 'enterpriseName'
            },
            {
              id: '4',
              label: '转出总金额',
              minWidth: '120',
              prop: 'amount'
            },
            {
              id: '5',
              label: '扣除总保理服务费',
              width: '140',
              prop: 'facAmount'
            },
            {
              id: '6',
              label: '转出结算金额',
              minWidth: '120',
              prop: 'actualAmount'
            },
            {
              id: '7',
              label: '审核人',
              prop: 'auditorName'
            },
            {
              id: '8',
              label: '结算时间',
              width: '160',
              prop: 'auditTime'
            },
            {
              id: '9',
              label: '操作',
              show: 'template',
              width: "100",
              prop: 'operation',
              fixed: "right"
            }
          ],
          data: []
        }
      },
      getList() {
        let info = formatData.clearObjEmptyPrama({...this.searchInfo, pageSize: this.pageSize, pageNum: this.currentPage})
        ajax.post(apis.factory.getSettlementPassList, info)
          .then(res => {
            if (res.success === true) {
              this.pageTotal = res.data.total
              if (res.data.dataList !== [] && res.data.dataList !== null) {
                this.dataTable.data = this.formatData(res.data.dataList)
              } else {
                this.dataTable.data = []
              }
              this.dataTable.loading = false
            }
          })
      },
      // 列表数据处理
      formatData(list) {
        return list.map(item => {
          return {
            id: item.id,
            applyNo: item.applyNo,
            applyTime: item.applyTime !== null && item.applyTime !== "" ? formatDate.timeFormat(item.applyTime) : "",
            auditTime: item.auditTime !== null && item.auditTime !== "" ? formatDate.timeFormat(item.auditTime) : "",
            enterpriseName: item.enterpriseName,
            amount: item.amount,
            facAmount: item.facAmount,
            actualAmount: item.actualAmount,
            auditorName: item.auditorName
          }
        })
      },
      // 查看详情
      showDetail(row) {
        this.isShowDetail = true
        this.$refs.AdvanceTransferSettlementDetail.getInfo(row)
        this.$refs.AdvanceTransferSettlementDetail.auditInfo = row;
      },
      // 导出
      exportInfo(){
        this.isSuccess = true;
        let info = formatData.clearObjEmptyPrama({...this.searchInfo, pageSize: this.pageSize, pageNum: this.currentPage})
        ajax.export(apis.factory.exportSettlementPassList, info)
          .then(res => {
            this.isSuccess = false;
          })
      },
      onSearch() {
        this.currentPage = 1
        this.getList()
      },
      // 搜索表单重置
      resetForm(formName) {
        // this.$refs[formName].resetFields();
        this.searchInfo = {...this.searchInfoBack}
      },
      // 切换页面
      currentPageChange(pageNo) {
        this.currentPage = pageNo
        this.getList()
      },
      // 切换页面条数
      pageSizeChange(pageNo) {
        this.pageSize = pageNo
        this.getList()
      },
      // 刷新页面
      refreshPage() {
        this.currentPage = 1
        this.pageSize = 10
        this.searchInfo = {...this.searchInfoBack}
        this.getList()
      }
    },
    created() {
      this.init()
      this.getList()
    }
  }
</script>

<style scoped>

</style>
